#include "view_outdoors.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "pressure.h"
#include "view_common.h"
#include "weather_ctrl.h"
#include "geomagnetism.h"
#include "lfs_file_manager.h"
#include "app_trace.h"
#include "nrf_delay.h"
#include "arm_math.h"
#include "language_text.h"
#define LOG(fmt, ...) // app_trace_log(fmt "\r\n", ##__VA_ARGS__)
#ifdef NO_OUTDOORS_UI
#else
const unsigned char bmp_a019_degree[] = {
    /* 数组大小：155 颜色数：15 图片：A019_compass_degree.bmp*/
    0x0d, 0x00, 0x0c, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x04, 0x21, 0xd3, 0x9c, 0xdb, 0xde, 0xdf, 0xff, 0x9e, 0xf7, 0x18, 0xc6, 0xcf, 0x7b, 0xcb, 0x5a, 0xd7, 0xbd, 0x9a, 0xd6, 0x51, 0x8c, 0x5d,
    0xef, 0x4d, 0x6b, 0x55, 0xad, 0x00, 0x81, 0x01, 0x02, 0x03, 0x04, 0x81, 0x05, 0x06, 0x07, 0x00, 0x83, 0x08, 0x05, 0x04, 0x86, 0x09, 0x00, 0x82, 0x03, 0x04, 0x82, 0x03, 0x0a, 0x05, 0x04,
    0x82, 0x0b, 0x00, 0x08, 0x04, 0x82, 0x02, 0x00, 0x81, 0x01, 0x0c, 0x04, 0x81, 0x0c, 0x00, 0x02, 0x04, 0x82, 0x00, 0x83, 0x0b, 0x04, 0x82, 0x00, 0x02, 0x04, 0x81, 0x0a, 0x00, 0x83, 0x0d,
    0x04, 0x82, 0x0d, 0x02, 0x04, 0x81, 0x0a, 0x00, 0x83, 0x0d, 0x04, 0x82, 0x0d, 0x02, 0x04, 0x82, 0x00, 0x83, 0x0b, 0x04, 0x82, 0x00, 0x08, 0x04, 0x82, 0x02, 0x00, 0x81, 0x01, 0x0c, 0x04,
    0x81, 0x03, 0x00, 0x81, 0x03, 0x04, 0x82, 0x03, 0x0a, 0x04, 0x83, 0x07, 0x00, 0x81, 0x08, 0x05, 0x04, 0x86, 0x0e, 0x00, 0x83, 0x01, 0x02, 0x03, 0x04, 0x81, 0x0c, 0x06, 0x0d, 0x00, 0x82,
};
const unsigned char bmp_n[] = {
    /* 数组大小：187 颜色数：14 图片：109-N-113-42.bmp*/
    0x0d, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x61, 0x58, 0xa6, 0xd9, 0xc3, 0x80, 0x00, 0x00, 0xe3, 0x88, 0x86, 0xd1, 0x20, 0x30, 0x45, 0xb9, 0x04, 0x99, 0x41, 0x48, 0x45, 0xa9, 0x65, 0xc1, 0x00, 0x18,
    0x86, 0xc9, 0x00, 0x01, 0x81, 0x02, 0x03, 0x85, 0x01, 0x81, 0x04, 0x00, 0x01, 0x81, 0x05, 0x06, 0x03, 0x84, 0x01, 0x81, 0x04, 0x00, 0x01, 0x82, 0x07, 0x03, 0x84, 0x01, 0x81, 0x04, 0x00, 0x01,
    0x83, 0x04, 0x03, 0x83, 0x01, 0x81, 0x04, 0x00, 0x01, 0x81, 0x08, 0x01, 0x81, 0x09, 0x03, 0x82, 0x01, 0x81, 0x04, 0x00, 0x01, 0x81, 0x00, 0x0a, 0x01, 0x0b, 0x03, 0x82, 0x01, 0x81, 0x04, 0x00,
    0x01, 0x81, 0x00, 0x0c, 0x0d, 0x01, 0x04, 0x03, 0x81, 0x01, 0x81, 0x04, 0x00, 0x01, 0x81, 0x00, 0x03, 0x00, 0x01, 0x81, 0x00, 0x03, 0x01, 0x81, 0x04, 0x00, 0x01, 0x81, 0x00, 0x03, 0x81, 0x08,
    0x01, 0x0d, 0x0c, 0x01, 0x81, 0x04, 0x00, 0x01, 0x81, 0x00, 0x03, 0x81, 0x0c, 0x0d, 0x01, 0x08, 0x01, 0x81, 0x04, 0x00, 0x01, 0x81, 0x00, 0x03, 0x82, 0x00, 0x01, 0x83, 0x04, 0x00, 0x01, 0x81,
    0x00, 0x03, 0x83, 0x04, 0x01, 0x82, 0x04, 0x00, 0x01, 0x81, 0x00, 0x03, 0x84, 0x0b, 0x01, 0x81, 0x04, 0x00, 0x01, 0x81, 0x00, 0x03, 0x84, 0x09, 0x01, 0x81, 0x04,
};

const unsigned char bmp_w[] = {
    /* 数组大小：275 颜色数：17 图片：A110-W.bmp*/
    0x14, 0x00, 0x0f, 0x00, 0x11, 0x00, 0x04, 0x21, 0x9a, 0xd6, 0x10, 0x84, 0x00, 0x00, 0x8a, 0x52, 0xcf, 0x7b, 0xc7, 0x39, 0xdb, 0xde, 0xdf, 0xff, 0x59, 0xce, 0x92, 0x94, 0x14, 0xa5, 0xd7,
    0xbd, 0x5d, 0xef, 0x96, 0xb5, 0x9e, 0xf7, 0x0c, 0x63, 0x00, 0x01, 0x81, 0x02, 0x03, 0x83, 0x04, 0x01, 0x81, 0x04, 0x03, 0x83, 0x05, 0x01, 0x81, 0x06, 0x03, 0x07, 0x08, 0x09, 0x03, 0x83,
    0x0a, 0x08, 0x81, 0x0b, 0x03, 0x83, 0x0c, 0x08, 0x0d, 0x03, 0x81, 0x0e, 0x08, 0x0f, 0x03, 0x83, 0x09, 0x08, 0x81, 0x07, 0x03, 0x83, 0x0d, 0x08, 0x0c, 0x03, 0x81, 0x10, 0x08, 0x81, 0x04,
    0x03, 0x82, 0x0f, 0x08, 0x82, 0x00, 0x03, 0x81, 0x06, 0x08, 0x81, 0x05, 0x03, 0x82, 0x0f, 0x08, 0x0a, 0x03, 0x81, 0x04, 0x08, 0x07, 0x01, 0x08, 0x05, 0x03, 0x81, 0x02, 0x08, 0x81, 0x00,
    0x03, 0x82, 0x09, 0x08, 0x09, 0x03, 0x81, 0x0b, 0x08, 0x0e, 0x0a, 0x08, 0x0e, 0x03, 0x81, 0x0c, 0x08, 0x01, 0x03, 0x83, 0x02, 0x08, 0x0f, 0x03, 0x81, 0x01, 0x08, 0x05, 0x04, 0x08, 0x07,
    0x03, 0x81, 0x0d, 0x08, 0x0a, 0x03, 0x83, 0x06, 0x08, 0x81, 0x04, 0x03, 0x08, 0x81, 0x00, 0x03, 0x0f, 0x08, 0x00, 0x06, 0x08, 0x81, 0x04, 0x03, 0x84, 0x07, 0x08, 0x0a, 0x10, 0x08, 0x07,
    0x03, 0x81, 0x09, 0x08, 0x05, 0x02, 0x08, 0x0d, 0x03, 0x85, 0x0e, 0x08, 0x09, 0x0b, 0x08, 0x0e, 0x03, 0x81, 0x0a, 0x08, 0x0c, 0x81, 0x08, 0x0c, 0x03, 0x85, 0x04, 0x08, 0x0f, 0x01, 0x08,
    0x10, 0x03, 0x81, 0x04, 0x08, 0x0d, 0x07, 0x08, 0x05, 0x03, 0x86, 0x0f, 0x08, 0x82, 0x03, 0x83, 0x0f, 0x08, 0x82, 0x00, 0x03, 0x86, 0x0c, 0x08, 0x81, 0x01, 0x03, 0x83, 0x0c, 0x08, 0x81,
    0x09, 0x03, 0x87, 0x02, 0x08, 0x81, 0x0b, 0x03, 0x83, 0x02, 0x08, 0x81, 0x0a, 0x03, 0x87, 0x00, 0x10, 0x81, 0x00, 0x03, 0x83, 0x00, 0x10, 0x81, 0x00, 0x03, 0x83,
};
const unsigned char bmp_e[] = {
    /* 数组大小：100 颜色数：12 图片：A111-E.bmp*/
    0x0b, 0x00, 0x0f, 0x00, 0x0c, 0x00, 0x9a, 0xd6, 0x8a, 0x52, 0xdf, 0xff, 0x0c, 0x63, 0xd7, 0xbd, 0x04, 0x21, 0x14, 0xa5, 0x00, 0x00, 0x5d, 0xef, 0x96,
    0xb5, 0x10, 0x84, 0xc7, 0x39, 0x00, 0x89, 0x01, 0x02, 0x89, 0x03, 0x02, 0x81, 0x04, 0x03, 0x86, 0x05, 0x02, 0x81, 0x06, 0x07, 0x87, 0x02, 0x81, 0x06,
    0x07, 0x87, 0x02, 0x81, 0x06, 0x07, 0x87, 0x02, 0x81, 0x08, 0x00, 0x85, 0x09, 0x07, 0x02, 0x88, 0x00, 0x07, 0x02, 0x81, 0x06, 0x07, 0x87, 0x02, 0x81,
    0x06, 0x07, 0x87, 0x02, 0x81, 0x06, 0x07, 0x87, 0x02, 0x81, 0x06, 0x07, 0x87, 0x02, 0x81, 0x08, 0x00, 0x86, 0x0a, 0x02, 0x89, 0x06, 0x03, 0x89, 0x0b,
};
const unsigned char bmp_s[] = {
    /* 数组大小：172 颜色数：17 图片：A112-S.bmp*/
    0x0c, 0x00, 0x0f, 0x00, 0x11, 0x00, 0x00, 0x00, 0x0c, 0x63, 0x14, 0xa5, 0x59, 0xce, 0xcf, 0x7b, 0x04, 0x21, 0x9a, 0xd6, 0xdf, 0xff, 0x5d, 0xef, 0x8a, 0x52, 0x96, 0xb5, 0x9e,
    0xf7, 0xc7, 0x39, 0xd7, 0xbd, 0x10, 0x84, 0xdb, 0xde, 0x92, 0x94, 0x00, 0x82, 0x01, 0x02, 0x03, 0x81, 0x02, 0x04, 0x00, 0x83, 0x05, 0x06, 0x07, 0x85, 0x08, 0x09, 0x00, 0x81,
    0x06, 0x07, 0x08, 0x02, 0x01, 0x81, 0x0a, 0x0b, 0x07, 0x08, 0x00, 0x09, 0x07, 0x81, 0x0c, 0x00, 0x83, 0x09, 0x07, 0x81, 0x04, 0x01, 0x07, 0x81, 0x0c, 0x00, 0x84, 0x0d, 0x06,
    0x0e, 0x05, 0x0b, 0x07, 0x0f, 0x01, 0x00, 0x87, 0x0e, 0x07, 0x82, 0x08, 0x0a, 0x04, 0x00, 0x85, 0x0c, 0x0a, 0x08, 0x07, 0x82, 0x08, 0x02, 0x05, 0x00, 0x85, 0x09, 0x0a, 0x08,
    0x07, 0x81, 0x08, 0x05, 0x00, 0x87, 0x01, 0x0b, 0x07, 0x0d, 0x81, 0x07, 0x06, 0x00, 0x85, 0x02, 0x07, 0x06, 0x0e, 0x07, 0x81, 0x09, 0x00, 0x84, 0x0d, 0x07, 0x06, 0x05, 0x08,
    0x07, 0x0b, 0x10, 0x01, 0x81, 0x04, 0x0d, 0x07, 0x81, 0x02, 0x00, 0x09, 0x08, 0x07, 0x86, 0x0d, 0x00, 0x82, 0x05, 0x0e, 0x0d, 0x06, 0x82, 0x02, 0x09, 0x00, 0x81,
};

void view_outdoors_base_display(void)
{
    int x = 62;
    int y = 28;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_A001_main_page_icon);
    x = 67;
    y = 173;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_A002_main_page_text);
    }

    show_button_up();
    show_button_right();
    show_button_down();
}
void view_outdoors_altitude_display()
{
    if (disp_ctrl.loop_cnt == 0)
    {
        float altitude = get_altitude();
        disp_ctrl.com_data.i_temp[0] = altitude;
        disp_ctrl.auto_refresh_time = 1000;
        if (disp_ctrl.com_data.i_temp[0] > 9999)
        {
            disp_ctrl.com_data.i_temp[0] = 9999;
        }
        else if (disp_ctrl.com_data.i_temp[0] < -9999)
        {
            disp_ctrl.com_data.i_temp[0] = -9999;
        }
    }
    int x = 85;
    int y = 26;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_A003_heigh_icon);

    int width = 0; //!< 计算居中
    if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        width += 22;
    }
    int num_abs = abs(disp_ctrl.com_data.i_temp[0]);
    width += get_num_digit(num_abs) * 22;

    width += 16 + 8;

    x = (240 - width) / 2;
    y = 139;
    if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        disp_draw_rect_color(x, y, x + 19, y + 1, RGB565_COLOR_WHITE);
        x += 22;
    }
    y = 118;
    x = disp_draw_user_image_num(x, y, num_abs, 22, num_N400_dig_19x42_TAB);

    x += 8;
    y = 143;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_A004_outdoor_unit_m);

    x = 84;
    y = 194;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_A005_heigh_text);
    }

    show_button_up();
    show_button_right();
    show_button_down();
}
void view_outdoors_pressure_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        float pressure = 0.f;
        for (int i = 0; i < 2; i++)
        {
            nrf_delay_ms(10);
            pressure = get_pressure();
            nrf_delay_ms(10);
            float temperature = get_temperature();
        }
        disp_ctrl.com_data.i_temp[0] = pressure / 100;
        disp_ctrl.auto_refresh_time = 1000;
    }
    int x = 89;
    int y = 25;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_A010_pressure_icon);

    int num_abs = abs(disp_ctrl.com_data.i_temp[0]);
    int width = get_num_digit(num_abs) * 22;
    width += 11 + 43;
    x = (240 - width) / 2;
    // y = 118;
    // x = disp_draw_user_image_num(x, y, num_abs, 22, num_N400_dig_19x42_TAB);
    // x = 74;
    y = 118;
    x = disp_draw_user_image_num(x, y, disp_ctrl.com_data.i_temp[0] / 10, 22, num_N400_dig_19x42_TAB);
    x += 2;
    disp_draw_user_image(x, y + 35, num_N411_dig_7x7_dot);
    x += 7;
    x += 2;
    x = disp_draw_user_image_num(x, y, disp_ctrl.com_data.i_temp[0] % 10, 22, num_N400_dig_19x42_TAB);

    y = 143;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_A012_pressure_unit_kpa);

    x = 74;
    y = 194;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_A011_pressure_text);
    }

    show_button_up();
    show_button_down();
}
void view_outdoors_temperature_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        float temperature = 0.f;
        for (int i = 0; i < 2; i++)
        {
            nrf_delay_ms(10);
            float pressure = get_pressure();
            nrf_delay_ms(10);
            temperature = get_temperature();
        }

        disp_ctrl.com_data.i_temp[1] = weather_get_temperature_type();
        if (disp_ctrl.com_data.i_temp[1] != WEATHER_TEMPERATURE_TYPE_C)
        {
            temperature = 32 + temperature * 1.8f;
        }
        disp_ctrl.com_data.i_temp[0] = temperature * 10;
        disp_ctrl.auto_refresh_time = 1000;
    }
    int x = 104;
    int y = 23;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_A006_tem_icon);
    x = 62;
    y = 139;
    if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        disp_draw_rect_color(x, y, x + 19, y + 1, RGB565_COLOR_WHITE);
    }
    int width = 0; //!< 计算居中
    if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        width += 22;
    }
    int num_abs = abs(disp_ctrl.com_data.i_temp[0]);
    width += get_num_digit(num_abs) * 22;
    width += 11 + 22;
    x = (240 - width) / 2;

    if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        y = 139;
        disp_draw_rect_color(x, y, x + 19, y + 1, RGB565_COLOR_WHITE);
        x += 22;
    }
    y = 118;
    x = disp_draw_user_image_num(x, y, abs(disp_ctrl.com_data.i_temp[0]) / 10, 22, num_N400_dig_19x42_TAB);
    x += 2;
    disp_draw_user_image(x, y + 35, num_N411_dig_7x7_dot);
    x += 7;
    x += 2;
    x = disp_draw_user_image_num_with_digits(x, y, abs(disp_ctrl.com_data.i_temp[0]) % 10, 1, 22, num_N400_dig_19x42_TAB);
    if (disp_ctrl.com_data.i_temp[1] != WEATHER_TEMPERATURE_TYPE_C)
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_A009_temperature_unit_f);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_A008_temperature_unit_c);
    }

    x = 51;
    y = 194;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 1;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_A007_tem_text);
    }

    show_button_up();
    show_button_down();
}
void view_outdoors_altitude_options_display(void)
{
    // if (disp_ctrl.loop_cnt == 0)
    // {
    //     disp_ctrl.com_data.i_temp[0] = get_altitude_calibration_option();
    // }
    int x = 10;
    int y = 0;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_A101_heigh_altimeter);
    x += 56;
    y += 32;
    if (disp_ctrl.com_data.uint8_temp[50])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[51]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_4, x, y, FILE_IMG_A101_heigh_altimeter_56_32);
    }

    for (int x = 44; x <= 44 + 152; x++)
    {
        disp_draw_point(x, 96, 0x3186);
        disp_draw_point(x, 143, 0x3186);
    }

    x = 35 - 15;
    y = 112;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_A108_yes);

    int first_index = 0;
    int second_index = 0;
    char const *first_text_str = 0;
    char const *second_text_str = 0;
    if (disp_ctrl.com_data.i_temp[0] == altitude_calibration_auto)
    {
        first_index = FILE_IMG_A103_heigh_autocal;
        second_index = FILE_IMG_A102_heigh_calibrate;
        if (disp_ctrl.com_data.uint8_temp[100])
        {
            first_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[101];
        }
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            second_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[151];
        }
    }
    else
    {
        first_index = FILE_IMG_A102_heigh_calibrate;
        second_index = FILE_IMG_A103_heigh_autocal;
        if (disp_ctrl.com_data.uint8_temp[100])
        {
            second_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[101];
        }
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            first_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[151];
        }
    }

    x = 70;
    y = 111;
    if (first_text_str)
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, first_text_str, 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, first_index);
    }
    x = 74;
    y = 173;
    if (second_text_str)
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, second_text_str, 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, x, y, second_index);
    }

    show_button_up();
    show_button_right();
    show_button_down();
}
void view_outdoors_altitude_set_0_display(void)
{
    int x = 10;
    int y = 0;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_A104_heigh_setelevation);
    x += 36;
    y += 32;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_4, x, y, FILE_IMG_A104_heigh_setelevation_36_32);
    }
    x = 87;
    y = 109;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_A106_heigh_select_number_thousands);

    // int abs_altitude = abs(disp_ctrl.com_data.i_temp[0]);
    x = 147;
    y = 123;

    // int thousand = abs_altitude / 1000 % 10;

    int remainder = abs(disp_ctrl.com_data.i_temp[0] % 1000);
    disp_draw_user_image_num_with_digits_gray_lucency(x, y, remainder, 3, 0x5acb, 26, num_N400_dig_19x42_TAB);
    x = 97;
    y = 116;
    int thousand = disp_ctrl.com_data.i_temp[0] / 1000 % 10;
    if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        for (int i = 0; i < 25; i++)
        {
            disp_draw_point(x - 29 + i, y + 29, RGB565_COLOR_WHITE);
            disp_draw_point(x - 29 + i, y + 29 + 1, RGB565_COLOR_WHITE);
        }
    }
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_N500_0_25x59 + abs(thousand));

    x = 103;
    y = 79;

    int previous_thousand = thousand + 1;
    int next_thousand = thousand - 1;
    bool is_previous_negative = false;
    bool is_next_negative = false;

    if (thousand == 0 && disp_ctrl.com_data.i_temp[0] >= 0)
    {
        next_thousand = 0;
        is_next_negative = true;
    }
    else if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        previous_thousand = 0;
        is_previous_negative = false;
    }
    if (previous_thousand < 0)
    {
        is_previous_negative = true;
    }
    if (next_thousand < 0)
    {
        is_next_negative = true;
    }
    if (previous_thousand <= 9)
    {
        if (is_previous_negative)
        {
            for (int i = 0; i < 12; i++)
            {
                disp_draw_point(x - 14 + i, y + 12, RGB565_COLOR_WHITE);
                disp_draw_point(x - 14 + i, y + 12 + 1, RGB565_COLOR_WHITE);
            }
        }
        disp_draw_user_image(x, y, num_N200_dig_12x24_TAB[abs(previous_thousand)]);
    }
    y = 191;
    if (next_thousand >= -9)
    {
        if (is_next_negative)
        {
            for (int i = 0; i < 12; i++)
            {
                disp_draw_point(x - 14 + i, y + 12, RGB565_COLOR_WHITE);
                disp_draw_point(x - 14 + i, y + 12 + 1, RGB565_COLOR_WHITE);
            }
        }
        disp_draw_user_image(x, y, num_N200_dig_12x24_TAB[abs(next_thousand)]);
    }
}
void view_outdoors_altitude_set_1_display(void)
{
    int x = 10;
    int y = 0;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_A104_heigh_setelevation);
    x += 36;
    y += 32;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_5, x, y, FILE_IMG_A104_heigh_setelevation_36_32);
    }

    x = 73;
    y = 109;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_A107_heigh_select_number);

    // int abs_altitude = abs(disp_ctrl.com_data.i_temp[0]);

    // int thousand = abs_altitude / 1000 % 10;
    x = 42;
    y = 126;
    if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        for (int i = 0; i < 12; i++)
        {
            disp_draw_point(x - 14 + i, y + 12, RGB565_COLOR_WHITE);
            disp_draw_point(x - 14 + i, y + 12 + 1, RGB565_COLOR_WHITE);
        }
    }
    disp_draw_user_image_gray_lucency(x, y, 0x5acb, num_N200_dig_12x24_TAB[abs(disp_ctrl.com_data.i_temp[0] / 1000 % 10)]);

    int remainder = abs(disp_ctrl.com_data.i_temp[0] % 1000);
    // int previous_altitude = disp_ctrl.com_data.i_temp[0] + 1;
    // int next_altitude = disp_ctrl.com_data.i_temp[0] - 1;

    int previous_num = 0;
    int next_num = 0;
    if (disp_ctrl.com_data.i_temp[0] >= 0)
    {
        if (remainder == 999)
        {
            previous_num = 0;
        }
        else
        {
            previous_num = remainder + 1;
        }
        if (remainder == 0)
        {
            next_num = 999;
        }
        else
        {
            next_num = remainder - 1;
        }
    }
    else if (disp_ctrl.com_data.i_temp[0] < 0)
    {
        if (disp_ctrl.com_data.i_temp[0] == -1)
        {
            previous_num = 999;
        }
        else if (remainder == 0)
        {
            previous_num = 999;
        }
        else
        {
            previous_num = remainder - 1;
        }
        if (disp_ctrl.com_data.i_temp[0] == -999)
        {
            next_num = 1;
        }
        else if (remainder == 999)
        {
            next_num = 0;
        }
        else
        {
            next_num = remainder + 1;
        }
    }

    x = 102;
    y = 81;
    if (disp_ctrl.com_data.i_temp[0] < 9999)
    {
        if (disp_ctrl.com_data.i_temp[0] < 0)
        {
            for (int i = 0; i < 12; i++)
            {
                disp_draw_point(x - 14 + i, y + 12, RGB565_COLOR_WHITE);
                disp_draw_point(x - 14 + i, y + 12 + 1, RGB565_COLOR_WHITE);
            }
        }
        disp_draw_user_image_num_with_digits(x, y, previous_num, 3, 15, num_N200_dig_12x24_TAB);
    }
    if (disp_ctrl.com_data.i_temp[0] > -9999)
    {
        y = 191;
        if (disp_ctrl.com_data.i_temp[0] < 0)
        {
            for (int i = 0; i < 12; i++)
            {
                disp_draw_point(x - 14 + i, y + 12, RGB565_COLOR_WHITE);
                disp_draw_point(x - 14 + i, y + 12 + 1, RGB565_COLOR_WHITE);
            }
        }
        disp_draw_user_image_num_with_digits(x, y, next_num, 3, 15, num_N200_dig_12x24_TAB);
    }
    x = 79;
    y = 116;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_N500_0_25x59 + remainder / 100);
    x += 30;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, x, y, FILE_IMG_N500_0_25x59 + remainder / 10 % 10);
    x += 30;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_4, x, y, FILE_IMG_N500_0_25x59 + remainder % 10);
}
void view_outdoors_geomagnetism_calibration_display(void)
{
    int x = 31;
    int y = 53;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_outdoors_geomagnetism_calibration_31_53);
    x = 24;
    y = 141;
    if (disp_ctrl.com_data.uint8_temp[100] && disp_ctrl.com_data.uint8_temp[150])
    {
        y -= 3;
        // 15 179 15+210
        // disp_show_font_string_utf8_area(15, 141, 15 + 210, 178, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
        disp_show_font_string_utf8_mid(141, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
        disp_show_font_string_utf8_mid(179, (char const *)(&disp_ctrl.com_data.uint8_temp[151]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_outdoors_geomagnetism_calibration_24_141);
    }
}
#ifdef USE_GEOMAGNETISM
void view_outdoors_geomagnetism_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.auto_close_delay = 2000;
        int angle = get_geomagnetism_angle();
        // int angle = disp_ctrl.auto_refresh_count % 360;
        disp_ctrl.auto_refresh_time = 100;
        disp_ctrl.com_data.i_temp[1] = geomagnetism_need_calibration();
        if (disp_ctrl.com_data.i_temp[0] != angle || disp_ctrl.auto_refresh_count == 0)
        {
            disp_ctrl.com_data.i_temp[0] = angle;
            float radian = angle * 3.1415926f / 180.f;
            float cos_angle = cosf(radian);
            float sin_angle = sinf(radian);
            int delta_x = 120 - 120;
            int delta_y = 32 - 120;
            if (angle == 0)
            {
                disp_ctrl.com_data.i_temp[2] = delta_x;
                disp_ctrl.com_data.i_temp[3] = delta_y;
            }
            else
            {

                // n
                disp_ctrl.com_data.i_temp[2] = delta_x * cos_angle + delta_y * sin_angle;
                disp_ctrl.com_data.i_temp[3] = delta_y * cos_angle - delta_x * sin_angle;
            }

            // s
            disp_ctrl.com_data.i_temp[4] = -disp_ctrl.com_data.i_temp[2];
            disp_ctrl.com_data.i_temp[5] = -disp_ctrl.com_data.i_temp[3];

            // w
            disp_ctrl.com_data.i_temp[6] = disp_ctrl.com_data.i_temp[3];
            disp_ctrl.com_data.i_temp[7] = -disp_ctrl.com_data.i_temp[2];

            // e
            disp_ctrl.com_data.i_temp[8] = -disp_ctrl.com_data.i_temp[6];
            disp_ctrl.com_data.i_temp[9] = -disp_ctrl.com_data.i_temp[7];

            for (int i = 2; i < 10; i++)
            {
                disp_ctrl.com_data.i_temp[i] += 120;
            }
            disp_ctrl.com_data.i_temp[2] -= 6;
            disp_ctrl.com_data.i_temp[3] -= 7;
            disp_ctrl.com_data.i_temp[4] -= 6;
            disp_ctrl.com_data.i_temp[5] -= 7;
            disp_ctrl.com_data.i_temp[7] -= 10;
            disp_ctrl.com_data.i_temp[8] -= 7;
            disp_ctrl.com_data.i_temp[9] -= 5;
            disp_ctrl.com_data.i_temp[10] -= 7;
        }
    }
    if (disp_ctrl.com_data.i_temp[1])
    {
        view_outdoors_geomagnetism_calibration_display();
        return;
    }
    int x = 0;
    int y = 0;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_A016_compass_bottom);

    x = disp_ctrl.com_data.i_temp[2];
    y = disp_ctrl.com_data.i_temp[3];
    disp_draw_user_image(x, y, bmp_n);

    x = disp_ctrl.com_data.i_temp[4];
    y = disp_ctrl.com_data.i_temp[5];
    disp_draw_user_image(x, y, bmp_s);

    x = disp_ctrl.com_data.i_temp[6];
    y = disp_ctrl.com_data.i_temp[7];
    disp_draw_user_image(x, y, bmp_w);

    x = disp_ctrl.com_data.i_temp[8];
    y = disp_ctrl.com_data.i_temp[9];
    disp_draw_user_image(x, y, bmp_e);

    uint8_t digit = get_num_digit(disp_ctrl.com_data.i_temp[0]);
    uint32_t width = 20 * digit + 12;
    x = (240 - width) / 2;
    y = 105;
    // 3+13;
    // #warning debug
    //     disp_ctrl.com_data.i_temp[0] = 888;
    x = disp_draw_user_image_num(x, y, disp_ctrl.com_data.i_temp[0], 20, num_N400_dig_19x42_TAB);
    x += 2;
    disp_draw_user_image(x, y, bmp_a019_degree);

    // num_N400_dig_19x42_TAB
}
#endif
int32_t view_outdoors_display(int32_t view)
{
    Expects(view >= view_outdoors);
    Expects(view < view_outdoors + VIEW_LEVEL_0_SUB_COUNT);
    switch (view)
    {
    case view_outdoors_base:
        view_outdoors_base_display();
        break;
    case view_outdoors_altitude:
        view_outdoors_altitude_display();
        break;
    case view_outdoors_altitude_options:
        view_outdoors_altitude_options_display();
        break;
    case view_outdoors_altitude_set_0:
        view_outdoors_altitude_set_0_display();
        break;
    case view_outdoors_altitude_set_1:
        view_outdoors_altitude_set_1_display();
        break;
    case view_outdoors_temperature:
        view_outdoors_temperature_display();
        break;
    case view_outdoors_pressure:
        view_outdoors_pressure_display();
        break;
        // case view_outdoors_geomagnetism_calibration:
        //     view_outdoors_geomagnetism_calibration_display();
        //     break;
#ifdef USE_GEOMAGNETISM
    case view_outdoors_geomagnetism:
        view_outdoors_geomagnetism_display();
        break;
#endif
    }
    return 0;
}
view_event_result_t view_outdoors_event(int32_t view, event_param_t param)
{
    Expects(view >= view_outdoors);
    Expects(view < view_outdoors + VIEW_LEVEL_0_SUB_COUNT);
    switch (param.event)
    {
    case event_view_entry:
    {
        switch (view)
        {
        case view_outdoors_altitude_set_0:
        {
            disp_ctrl.com_data.i_temp[0] = get_altitude();
            if (disp_ctrl.com_data.i_temp[0] > 9999)
            {
                disp_ctrl.com_data.i_temp[0] = 9999;
            }
            else if (disp_ctrl.com_data.i_temp[0] < -9999)
            {
                disp_ctrl.com_data.i_temp[0] = -9999;
            }
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Set_Elevation, buff, buff_len);
            return view_event_result_handled;
        }
        case view_outdoors_altitude_set_1:
        {
            // disp_ctrl.com_data.i_temp[0] = get_altitude();
            // if (disp_ctrl.com_data.i_temp[0] > 9999)
            // {
            //     disp_ctrl.com_data.i_temp[0] = 9999;
            // }
            // else if (disp_ctrl.com_data.i_temp[0] < -9999)
            // {
            //     disp_ctrl.com_data.i_temp[0] = -9999;
            // }
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Set_Elevation, buff, buff_len);
            return view_event_result_handled;
        }
        case view_outdoors_altitude_options:
        {
            disp_ctrl.com_data.i_temp[0] = get_altitude_calibration_option();
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[51];
            uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[100] - buff;
            disp_ctrl.com_data.uint8_temp[50] = get_language_text(language_text_index_Altimeter, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[101];
            buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Auto_cal, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[151];
            buff_len = &disp_ctrl.com_data.uint8_temp[200] - buff;
            disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_Calibrate, buff, buff_len);
            return view_event_result_handled;
        }
#ifdef USE_GEOMAGNETISM
        case view_outdoors_geomagnetism:
        {
            geomagnetism_start();
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_calibrate_compass, buff, buff_len);
            buff = &disp_ctrl.com_data.uint8_temp[151];
            buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_turn_tilf_in_a_figure_8, buff, buff_len);
            return view_event_result_handled;
        }
#endif
        case view_outdoors_base:
        {
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Outdoors, buff, buff_len);
            return view_event_result_handled;
        }
        case view_outdoors_altitude:
        {
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Height, buff, buff_len);
            return view_event_result_handled;
        }
        case view_outdoors_temperature:
        {
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Temperature, buff, buff_len);
            return view_event_result_handled;
        }
        case view_outdoors_pressure:
        {
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Pressure, buff, buff_len);
            return view_event_result_handled;
        }
        default:
            break;
        }
        break;
    }
    case event_view_exit:
    {
        switch (view)
        {
#ifdef USE_GEOMAGNETISM
        case view_outdoors_geomagnetism:
            geomagnetism_stop();
            break;
#endif
        default:
            break;
        }
        break;
    }
    case event_move_previous_view:
    {
        switch (view)
        {
        case view_outdoors_level_1_begin:
            display_show(view_outdoors_level_1_end - VIEW_LEVEL_1_SUB_COUNT, DISP_MODE_UP_MOVE);
            return view_event_result_handled;
        case view_outdoors_altitude_options:
            disp_ctrl.com_data.i_temp[0] = !disp_ctrl.com_data.i_temp[0];
            display_set_update_request(view_outdoors_altitude_options, 0);
            return view_event_result_handled;
        case view_outdoors_altitude_set_0:
            if (disp_ctrl.com_data.i_temp[0] < 9000)
            {
                if (disp_ctrl.com_data.i_temp[0] < 0 && disp_ctrl.com_data.i_temp[0] > -1000)
                {
                    disp_ctrl.com_data.i_temp[0] = -disp_ctrl.com_data.i_temp[0];
                }
                else
                {
                    disp_ctrl.com_data.i_temp[0] += 1000;
                }
                display_set_update_request(view_outdoors_altitude_set_0, 0);
            }
            return view_event_result_handled;
        case view_outdoors_altitude_set_1:
        {
            int remainder = disp_ctrl.com_data.i_temp[0] % 1000;
            int new_remainder = 0;
            if (remainder == 999)
            {
                new_remainder = 0;
            }
            else if ((disp_ctrl.com_data.i_temp[0] == -1) || (disp_ctrl.com_data.i_temp[0] < 0 && remainder == 0))
            {
                new_remainder = -999;
            }
            else
            {
                new_remainder = remainder + 1;
            }
            disp_ctrl.com_data.i_temp[0] = disp_ctrl.com_data.i_temp[0] - remainder + new_remainder;
            display_set_update_request(view_outdoors_altitude_set_1, 0);
            return view_event_result_handled;
        }
        }
        break;
    }
    case BUTTON_EVENT_LONG_PRESS:
    case BUTTON_EVENT_LONG_PRESS_KEEP:
    {
        switch (view)
        {
        case view_outdoors_altitude_set_1:
        {
            switch (param.source)
            {
#if defined(BUTTON_TOP)
            case event_source_button_top:
            {
                // LOG("altitude +10");
                int remainder = disp_ctrl.com_data.i_temp[0] % 1000;
                int new_remainder = 0;
                // if (disp_ctrl.com_data.i_temp[0] < 9990)
                // {
                //     disp_ctrl.com_data.i_temp[0] += 10;
                //     display_set_update_request(view_outdoors_altitude_set_1, 0);
                // }
                // else
                // {
                //     disp_ctrl.com_data.i_temp[0] = 9999;
                //     display_set_update_request(view_outdoors_altitude_set_1, 0);
                // }
                if (disp_ctrl.com_data.i_temp[0] == -10)
                {
                    new_remainder = -990;
                }
                else if (remainder <= 999 && remainder >= 990)
                {
                    new_remainder = (remainder + 10) % 1000;
                }
                else if (disp_ctrl.com_data.i_temp[0] < 0 && remainder <= 0 && remainder >= -9)
                {
                    new_remainder = (remainder + 10) - 1000;
                }
                else
                {
                    new_remainder = remainder + 10;
                }
                disp_ctrl.com_data.i_temp[0] = disp_ctrl.com_data.i_temp[0] - remainder + new_remainder;
                display_set_update_request(view_outdoors_altitude_set_1, 0);
                break;
            }
#endif
#if defined(BUTTON_BOTTOM)
            case event_source_button_bottom:
                // LOG("altitude -10");
                // if (disp_ctrl.com_data.i_temp[0] > -9990)
                // {
                //     disp_ctrl.com_data.i_temp[0] -= 10;
                //     display_set_update_request(view_outdoors_altitude_set_1, 0);
                // }
                // else
                // {
                //     disp_ctrl.com_data.i_temp[0] = -9999;
                //     display_set_update_request(view_outdoors_altitude_set_1, 0);
                // }
                {
                    int remainder = disp_ctrl.com_data.i_temp[0] % 1000;
                    int new_remainder = 0;
                    if (disp_ctrl.com_data.i_temp[0] == -990)
                    {
                        new_remainder = -10;
                    }
                    else if (remainder >= 0 && remainder <= 10)
                    {
                        new_remainder = (remainder - 10) + 1000;
                    }
                    else if (disp_ctrl.com_data.i_temp[0] < 0 && remainder >= -999 && remainder <= -900)
                    {
                        new_remainder = (remainder - 10) % 1000;
                    }
                    else
                    {
                        new_remainder = remainder - 10;
                    }
                    disp_ctrl.com_data.i_temp[0] = disp_ctrl.com_data.i_temp[0] - remainder + new_remainder;
                    display_set_update_request(view_outdoors_altitude_set_1, 0);

                    break;
                }
#endif
            }
            return view_event_result_handled;
        }
        }
        break;
    }

    case event_move_next_view:
    {
        switch (view)
        {
        case (view_outdoors_level_1_end - VIEW_LEVEL_1_SUB_COUNT):
            display_show(view_outdoors_level_1_begin, DISP_MODE_DOWN_MOVE);
            return view_event_result_handled;
        case view_outdoors_altitude_set_0:
            if (disp_ctrl.com_data.i_temp[0] > -9000)
            {
                if (disp_ctrl.com_data.i_temp[0] == 0)
                {
                    disp_ctrl.com_data.i_temp[0] = -1;
                }
                else if (disp_ctrl.com_data.i_temp[0] > 0 && disp_ctrl.com_data.i_temp[0] < 1000)
                {
                    disp_ctrl.com_data.i_temp[0] = -disp_ctrl.com_data.i_temp[0];
                }
                else
                {
                    disp_ctrl.com_data.i_temp[0] -= 1000;
                }
                display_set_update_request(view_outdoors_altitude_set_0, 0);
            }
            return view_event_result_handled;
        case view_outdoors_altitude_set_1:
        {
            int remainder = disp_ctrl.com_data.i_temp[0] % 1000;
            int new_remainder = 0;
            if (disp_ctrl.com_data.i_temp[0] == -999)
            {
                new_remainder = -1;
            }
            else if (remainder == -999)
            {
                new_remainder = 0;
            }
            else if (disp_ctrl.com_data.i_temp[0] >= 0 && remainder == 0)
            {
                new_remainder = 999;
            }
            else
            {
                new_remainder = remainder - 1;
            }
            disp_ctrl.com_data.i_temp[0] = disp_ctrl.com_data.i_temp[0] - remainder + new_remainder;
            display_set_update_request(view_outdoors_altitude_set_1, 0);
            return view_event_result_handled;
        }
        case view_outdoors_altitude_options:
            disp_ctrl.com_data.i_temp[0] = !disp_ctrl.com_data.i_temp[0];
            display_set_update_request(view_outdoors_altitude_options, 0);
            return view_event_result_handled;
        }
        break;
    }
    case event_move_level_down:
    {
        switch (view)
        {
        case view_outdoors_temperature:
        case view_outdoors_pressure:
            // case view_outdoors_geomagnetism_calibration:
#ifdef USE_GEOMAGNETISM
        case view_outdoors_geomagnetism:
            return view_event_result_handled;
#endif
        case view_outdoors_altitude_options:
            if (disp_ctrl.com_data.i_temp[0] == altitude_calibration_auto)
            {
                set_altitude_calibration_option((altitude_calibration_t)disp_ctrl.com_data.i_temp[0]);
            }
            if (disp_ctrl.com_data.i_temp[0] == altitude_calibration_auto)
            {
                display_show(view_outdoors_altitude, DISP_MODE_NORMAL);
            }
            else
            {
                display_show(view_outdoors_altitude_set_0, DISP_MODE_NORMAL);
            }
            return view_event_result_handled;
        case view_outdoors_altitude_set_0:
            display_show(view_outdoors_altitude_set_1, DISP_MODE_NORMAL);
            return view_event_result_handled;
        case view_outdoors_altitude_set_1:
        {
            float sea_level_pressure = calculate_sea_level_pressure(disp_ctrl.com_data.i_temp[0]);
            // char buff[64] = {0};
            // sprintf(buff, "set %u sea level pressure %f", disp_ctrl.com_data.i_temp[0], sea_level_pressure);
            if (sea_level_pressure != 0.f)
            {
                set_manual_sea_level_pressure(sea_level_pressure);
                display_show(view_outdoors_altitude, DISP_MODE_NORMAL);
            }
            return view_event_result_handled;
        }
        }
        break;
    }
    }

    return view_event_result_not_handled;
}
#endif
